import { _decorator, Button, Component, EventTouch, Label } from 'cc';
const { ccclass, property } = _decorator;
import { Databus } from '../core/Databus';
import DataEventReport from '../platform/DataEventReport';

const databus = Databus.Instance();

@ccclass('TopCoinNavigation')
export class TopCoinNavigation extends Component {
  private earnCoinButton: Button = null;
  private coinLabel: Label  = null;
  protected onLoad() {
    this.earnCoinButton = this.node.getChildByName('Coin').getComponent(Button);
    this.earnCoinButton.node.on(Button.EventType.CLICK, this.toEarnCoinPage, this);

    this.coinLabel = this.node.getChildByName('Coin').getChildByName('Label').getComponent(Label);
  }

  protected update(deltaTime: number) {
    this.coinLabel.string = `${databus.selfInfo.goldCoin}`;
  }
  public toEarnCoinPage(e: EventTouch) {
    DataEventReport.Instance().reportComponentEvent(databus.sceneStack.currentPageName(), 'EarnCoinPage');
    databus.sceneStack.toEarnCoinPage();
  }
}